$(function () {
    var portaluserno = getCookie('portaluserno')
    var configInfo = InitialParameter("/Config.json")
    if (sessionStorage.getItem('myApplication_curr') != null) {
        sessionStorage.setItem('myApplication_curr',1)
    }
    // let modelApi = configInfo["modelTree"].type + '://' + configInfo["modelTree"].value  
    var modelApi = getBaseplatformPort()
    var uploadApi = configInfo["fileUploadOrigin"].type + '://' + configInfo["fileUploadOrigin"].value
    var shaType = true
    var applicationName = true 
    var resetType = false  // 重置开关 
    var queryData = [] // 查询到的值 
    var oldName = ''
    var tableData // 应用资源管理大表  
    var addData // 存储点击当前按钮的需要在表单回显的值   
    var selectdata, // 选择数据库
        datatable, // 选择数据表
        analysisToolsData, // 分析工具
        applicationClassificationData // 应用分类  

    var paramsObj = {
        registerUser: portaluserno,
        systemType: '',
        analysisTools: '',
        systemStatus: 1,
        name: '',
        analysisToolValus: '',
        databaseName: '',
        tableName: '',
        type: '',
        id: '',
        shpPath: '',
        description: ''
    }
    $(document).ready(function () {
        if (!portaluserno) {
            location.href = "/"
        } else {
            getData()
            whetherUploadUrl()
        }
    })

    function whetherUploadUrl() {
        if (shaType) {
            paramsObj.type = 'table'
            $('#selectDatabase').attr('lay-verify', 'required')
            $('#selectDatabaseTable').attr('lay-verify', 'required')
        } else {
            paramsObj.type = 'shp'
        }
    }
    layui.use(['form', 'upload', 'element', 'table', 'layer'], function () {
        var form = layui.form
        var upload = layui.upload
        var element = layui.element
        var table = layui.table
        var layer = layui.layer // 弹框表现
        var uploadInst = upload.render({
            elem: '#uploadFiles',
            async: false,
            xhrFields: {
                withCredentials: true
            },
            url: uploadApi + "/sw/upload/uploadZip",
            accept: 'file',
            exts: 'zip',
            header: {
                "Access-Control-Allow-Credentials": true,
                "Content-Type": "application/x-www-form-urlencoded"
            },
            data: {
                userNo: portaluserno
            },
            done: function (res) {
                if (res.code == 200) {
                    paramsObj.shpPath = res.data
                    $('#selectDatabase').removeAttr('lay-verify')
                    $('#selectDatabaseTable').removeAttr('lay-verify')
                    $('#selectDatabase').attr('disabled', true)
                    $('#selectDatabaseTable').attr('disabled', true)
                    layer.msg(res.msg)
                    shaType = false
                    whetherUploadUrl()
                }
            },
            error: function () {
                console.log('失败');
                //请求异常回调
            }
        });
        var updateApplyTAG = false
        form.on('submit(component-form-demo1)', function(data){
            updateApplyTAG = true;
        })
        table.on('tool(demo)', function (obj) {
            // 修改按钮点击
            if (obj.event == 'modifyThe') {
                oldName = obj.data.NAME
                $.ajax({
                    type: "post",
                    async: false,
                    url: modelApi + "apply/getApplyById",
                    data: {
                        id: obj.data.ID
                    },
                    datatype: "json",
                    success: function (res) {
                        let data = JSON.parse(res)
                        if (data.code == 200) {
                            let datasourcePath = data.data.datasourcePath
                            addData = data.data 
                            $('#description').val(addData.description)
                        } else {
                            layui.layer.msg(data.msg, {
                                time: 1000,
                                icon: 5,
                                shift: 6
                            })
                        }
                    }
                })
                // 把字母转换为汉字
                var spatialData = getDataDict("spatial");
                for (key in spatialData) {
                    var oneData = spatialData[key];
                    if (addData.systemType == '' + oneData.ZDVALUE + "") {
                        addData.systemType = oneData.ZDTITLE
                    }
                }
                // 结束 
                rightTable(addData.databaseName) // 获取选择数据表的函数   
                // 判断选择数据表有没有内容，有内容上传按钮禁用，没有内容可以点
                if (addData.databaseName) { // 有内容 
                    $('#uploadFiles').attr('disabled', true)
                    $('#uploadFiles').addClass('layui-btn-disabled')
                    // 选择数据库填值
                    selectdata.map(item => {
                        if (item.NAME == addData.databaseName) {
                            $(`#selectDatabase option[label=${addData.databaseName}]`).attr('selected', true)
                        }
                    })
                    // 选择数据表填值
                    datatable.map(item => {
                        if (item.TABLE_NAME == addData.tableName) {
                            $(`#selectDatabaseTable option[label=${addData.tableName}]`).attr('selected', true)
                        }
                    })
                } else { // 没有内容
                    $('#uploadFiles').attr('disabled', false)
                    $('#uploadFiles').removeClass('layui-btn-disabled')
                    $('#selectDatabaseTable').empty();
                }
                // 应用名称填值
                $('.applicationName').val(obj.data.NAME)
                // 分析工具的填值
                analysisToolsData.map(item => {
                    if (item.ZDTITLE === addData.analysisTools) {
                        $('#analysisTools option').removeAttr("selected");
                        $(`#analysisTools option[label=${item.ZDTITLE}]`).attr('selected', true)
                    }
                })
                // 应用分类的填值 
                applicationClassificationData.map(item => {
                    if (item.ZDTITLE == addData.systemType) {
                        $(`#applicationClassification option[label=${addData.systemType}]`).attr('selected', true)
                    }
                })
                layui.form.render('select'); // 表重新渲染  
                // 赋值保存 需要的参数  
                let newSystemType
                for (key in spatialData) {
                    var oneData = spatialData[key];
                    if (addData.systemType == '' + oneData.ZDTITLE + "") {
                        newSystemType = oneData.ZDVALUE
                    }
                }
                layer.open({
                    type: 1,
                    title: "修改",
                    shadeClose: true,
                    content: $('#modifyThe'),
                    btn: ['确定'],
                    yes: function (index, layero) {
                        $("#submit_btn").click();
                        if(updateApplyTAG){
                            if ($('#selectDatabase').val() == '' && shaType == true) {
                                layer.msg('请上传文件或者选择数据库', {
                                    icon: 0,
                                    time: 1000,
                                    shade: [0.5, '#000', true]
                                });
                            } else if (!applicationName) {
                                layui.layer.msg('应用名称重复,请重新输入', {
                                    icon: 0,
                                    time: 1000,
                                    shade: [0.5, '#000', true]
                                })
                            } else {
                                whetherUploadUrl()
                                let obj = {}
                                let analyName = $('#analysisTools').val()
                                let analyNameData = analyName.split(',')
                                obj.name = $('.applicationName').val() // 应用说明 
                                obj.systemType = newSystemType
                                obj.analysisTools = addData.analysisTools == analyNameData[0] ? addData.analysisTools : paramsObj.analysisTools
                                obj.analysisToolValus = addData.analysisTools == analyNameData[0] ? addData.analysisToolValus : paramsObj.analysisToolValus
                                obj.id = addData.id
                                obj.databaseName = $('#selectDatabase').val() // 数据库名 
                                obj.tableName = $('#selectDatabaseTable').val() //  数据库表名 
                                obj.description = $('#description').val() // 应用说明  
                                obj.registerUser = portaluserno,
                                    obj.systemStatus = 1,
                                    obj.type = paramsObj.type,
                                    obj.shpPath = paramsObj.shpPath,

                                    $.ajax({
                                        type: "post",
                                        async: false,
                                        url: modelApi + "apply/updateApply",
                                        data: obj,
                                        datatype: "json",
                                        success: function (res) {
                                            let data = JSON.parse(res)
                                            if (data.code == 200) {
                                                if ($('#ipt_search').val() != '') {
                                                    getDataTable() 
                                                    queryMethods ($('.applicationName').val()) 
                                                    drawingTable(queryData, ['NAME', 'ANALYSIS_TOOLS', 'REGISTER_DATE']) 
                                                } else {
                                                    getDataTable()
                                                    drawingTable(tableData, ['NAME', 'ANALYSIS_TOOLS', 'REGISTER_DATE'])
                                                }
                                                layer.close(index);
                                                layer.msg(data.msg, {
                                                    icon: 1,
                                                    time: 1500,
                                                    shade: [0.5, '#000', true]
                                                });
                                            } else {
                                                layui.layer.msg(data.msg, {
                                                    time: 1000,
                                                    icon: 5,
                                                    shift: 6
                                                })
                                            }
                                            layui.form.render("select");
                                        }
                                    });
                            }
                            updateApplyTAG = false;
                        }
                        
                    },
                    // 关闭弹框的回调函数
                    end: function (res) {
                        $("#modifyThe").css("display", 'none');
                    },
                });
            } else if (obj.event == 'authorization') {
                // 授权按钮点击  
                initAttrTableLayer(obj.data)
                let layerId
                layerId = obj.data.ID
                let powerGetData = authoGetData (obj.data.ID) 
                // 授权页面弹框
                layer.open({
                    type: 1,
                    title: "授权",
                    shadeClose: true,
                    content: $('#authorizationDiv'),
                    area:['500px','720px'],
                    end: function (res) {
                        $("#authorizationDiv").css("display", 'none');
                    },
                    btn: ['保存'],
                    yes: function (index, layero) {
                        authorizationSave(obj.data.ID, powerGetData, powerGetData) 
                        return false
                    },
                    done: function (res, curr, count) {
                        powerGetData = layui.table.cache[layerId];
                    }
                });
                //监听是否可查操作
                form.on('switch(encrypt)', function (obj) {
                    let index = obj.othis.parents('tr').attr("data-index"); 
                    let pageIndex = ''
                    let page = $("#authorizationDiv .layui-laypage-skip").find("input").val() 
                    let size = $("#authorizationDiv .layui-laypage-limits").find("option:selected").val() //分页数目 
                    if (page && size) {
                        pageIndex = page == 1 ? index * 1 : ((size * (page - 1)) * 1)  + (index * 1)
                    } else {
                        pageIndex = index 
                    }
                    if (obj.elem.checked) {
                        powerGetData[pageIndex].STATUS = "1";
                    } else {
                        powerGetData[pageIndex].STATUS = "0";
                    }
                });  
                // 查询
                $('#authorizationBtn_setch').click(function () {
                    authoGetData (obj.data.ID,$('#authorizationBtn_input').val())
                })
            } else if (obj.event == 'deleteContent') {
                // 删除按钮点击 
                layer.confirm("确认要删除吗，删除后不能恢复", {
                    title: "删除"
                }, function (index) {
                    if (index) {
                        delectName(obj.data.NO)
                        layer.close(index);
                    }
                })
            }
        }) 
        drawingTable(tableData, ['NAME', 'ANALYSIS_TOOLS', 'REGISTER_DATE']) // 页面加载调用的函数 layui-form-onswitch 
        form.on('switch(switchGoodsID)', function(data){
            let status = null // 启动1 暂停2   
            let applyId = this.id
            if (data.elem.checked == false ) {
                status = 2
            } else {
                status = 1
            }
            $.ajax({
                type: "post",
                async: false,
                url: modelApi + "apply/updateApplyStatus",
                data:{
                    userNo:portaluserno,
                    status,applyId
                },
                datatype: "json",
                success: function (res) {
                    let data = []
                    if (typeof res == 'string') {
                        data = JSON.parse(res)
                    } else {
                        data = res 
                    }
                    if (data.code == 200) { 
                        getDataTable () 
                        drawingTable(tableData, ['NAME', 'ANALYSIS_TOOLS', 'REGISTER_DATE']) // 页面加载调用的函数 layui-form-onswitch 
                        layui.layer.msg('运行管理状态修改成功', {icon: 1,time: 1000,shade : [0.5 , '#000' , true]});
                    }
                }
            })
        }); 
        // 获取授权信息 
        function authoGetData (id,name) { 
            let powerData = [] 
            let data = {}
            if (name) {
                data = { 
                    applyId:id,
                    userName:name
                } 
            } else {
                data = {
                    applyId: id
                }
            } 
            let elemName = '#attrTable' + id
            $.ajax({
                type: "post",
                async: false,
                url: modelApi + "power/getApplyPowers",
                data: data,
                datatype: "json",
                success: function (res) {
                    let data = JSON.parse(res)
                    powerData = data.data
                    if (data.code == 200) {
                        // 授权管理表
                        table.render({
                            elem: elemName,
                            data: powerData,
                            page: true, 
                            cols: [
                                [{
                                    field: 'NAME',
                                    width: 150,
                                    title: '部门人员',
                                    align: 'center'
                                }, {
                                    field: 'authorizations',
                                    width: 150,
                                    title: '授权',
                                    align: 'center',
                                    toolbar: '#authorizations-table-operate'
                                }]
                            ]
                        });
                        layui.table.resize('attrTable' + id);
                    }
                }
            })
            return powerData
        }
        // 授权保存 
        let types = '1'
        layui.form.on('switch(encrypt)', function (data) {
            if (this.checked == true) {
                types = '1'
            } else {
                types = '0'
            }
        })
        // 授权 
        function authorizationSave(applyId, data, powersData) {
            let typeData = []
            let roleData = []
            for (let i = 0; i < data.length; i++) {
                if (data[i].STATUS == '') {
                    data[i].STATUS = '0'
                }
                typeData.push(data[i].STATUS)
                roleData.push(data[i].NO)
            }
            let types = typeData.join(',')
            let roles = roleData.join(',')
            let arr = powersData.map(item => {
                return item.NO
            })
            let no = arr.join(',')
            console.log(no);

            $.ajax({
                type: "post",
                async: false,
                url: modelApi + "power/updateApplyPower",
                data: {
                    applyId: applyId,
                    userName: no,
                    type: types
                },
                datatype: "json",
                success: function (res) {
                    let data = JSON.parse(res)
                    if (data.code == 200) {
                        layer.closeAll()
                        layer.msg(data.msg, {icon: 1,time: 1000,shade : [0.5 , '#000' , true]});
                        drawingTable(tableData, ['NAME', 'ANALYSIS_TOOLS', 'REGISTER_DATE'])
                    } else {
                        layui.layer.msg(data.msg, {
                            time: 1000,
                            icon: 5,
                            shift: 6
                        })
                    }
                }
            })
            return false
        }
        // 删除用户 
        function delectName(applyId) {
            $.ajax({
                type: "post",
                async: false,
                url: modelApi + "apply/deleteApply",
                data: {
                    applyId
                },
                datatype: "json",
                success: function (res) {
                    let data = JSON.parse(res)
                    if (data.code == 200) {
                        layui.layer.msg(data.msg)
                        getDataTable() // 重新发起获取表格的请求
                        drawingTable(tableData, ['NAME', 'ANALYSIS_TOOLS', 'REGISTER_DATE'])
                    } else {
                        layui.layer.msg(data.msg, {
                            time: 1000,
                            icon: 5,
                            shift: 6
                        })
                    }
                }
            })
        }
        // 选择数据表内容的获取 
        form.on('select(typeData)', function (data) {
            rightTable(data.value)
        });
        form.on('switch(typeDataTable)', function (data) {
            if (data.value != '') {
                paramsObj.tableName = data.value
                $('#uploadFiles').attr('disabled', true)
                $('#uploadFiles').addClass('layui-btn-disabled')
            } else {
                $('#uploadFiles').attr('disabled', false)
            }
        })
        // 分析工具 
        form.on('select(analysisTools)', function (data) {
            let arr = data.value.split(',')
            paramsObj.analysisTools = arr[0]
            paramsObj.analysisToolValus = arr[1]
        })
        // 应用分类
        form.on('select(applicationClassification)', function (data) {
            paramsObj.systemType = data.value
        })
    });

    function initAttrTableLayer(data) {
        let attrTabHtml = ''  
        if (data) { 
            attrTabHtml += `
            <div class="layui-form-item" style="display:flex;"}>
                <div style="height:50px;width:80%;" class="layui-input-inline">
                    <input type="text" name="title" required  lay-verify="required" id="authorizationBtn_input" placeholder="请输入名称" autocomplete="off" class="layui-input">
                </div> 
                <div style="width:15px;">
                    <button class="layui-btn layui-btn-normal" id="authorizationBtn_setch">查询</button>
                </div>
            </div> 
            
            `
            attrTabHtml += '<table  id="attrTable' + data.ID + '" lay-filter="attrTable' + data.ID + '"></table>'
        }
        $('#authorizationDiv').html(attrTabHtml)
    }
    let zhutiList = []
    // 右边选择表内容的获取 
    // 右边选择表内容的获取 
    function rightTable(value) {
        if (value) {
            $('#uploadFiles').attr('disabled', true)
            $('#uploadFiles').addClass('layui-btn-disabled')
            paramsObj.dataBaseName = value
            let userName = portaluserno
            let tableName = value
            $.ajax({
                type: "post",
                async: false,
                url: modelApi + "dababaseConnect/getTableByName",
                data: {
                    userName,
                    tableName
                },
                datatype: "json",
                success: function (res) {
                    let data = JSON.parse(res)
                    if (data.code == 200) {
                        datatable = data.data
                        data.data.map(item => {
                            $('#selectDatabaseTable').append(`<option value="${item.TABLE_NAME}" label="${item.TABLE_ALIAS}">${item.TABLE_NAME}</option>`)
                        })
                    } else {
                        layui.layer.msg(data.msg, {
                            time: 1000,
                            icon: 5,
                            shift: 6
                        })
                    }
                }
            });
            layui.form.render("select");
        } else {
            $('#uploadFiles').attr('disabled', false)
            $('#uploadFiles').removeClass('layui-btn-disabled')
            $('#selectDatabaseTable').empty();
            layui.form.render("select");
        }

        layui.form.render("select");
    }
    // 表单失去焦点 验证名字是否重复
    $('.applicationName').on('blur', function () {
        let name = $('.applicationName').val()
        if ($('.applicationName').val() == addData.name) {
            applicationName = true
        } else {
            if (name != '' && $('.applicationName').val() != addData.name) {
                $.ajax({
                    type: "post",
                    async: false,
                    url: modelApi + "apply/getApplyByName",
                    data: {
                        name
                    },
                    datatype: "json",
                    success: function (res) {
                        let data = JSON.parse(res)
                        if (data.code == 500) {
                            applicationName = true
                        } else {
                            applicationName = false
                            layui.layer.msg('应用名称重复', {
                                time: 1000,
                                icon: 5,
                                shift: 6
                            })
                        }
                    }
                })
            }
        }

    })

    function getDataTable() {
        // 表数据的获取
        $.ajax({
            type: "post",
            async: false,
            url: modelApi + "apply/getApplyByUserNo",
            data: {
                userNo: portaluserno
            },
            datatype: "json",
            success: function (res) {
                let data = JSON.parse(res)
                if (data.code == 200) {
                    tableData = data.data
                    tableData.map(item => {
                        return item.REGISTER_DATE = formatDate(item.REGISTER_DATE)
                    })
                    tableData.sort(compare('REGISTER_DATE')); 
                } else {
                    layui.layer.msg(data.msg, {
                        time: 1000,
                        icon: 5,
                        shift: 6
                    })
                }
                layui.form.render("select");
            }
        });
    }

    function getData() {
        // 应用资源管理数据表格数据的请求
        getDataTable()

        // 选择数据库第一表格数据的获取
        $.ajax({
            type: "post",
            async: false,
            url: modelApi + "dababaseConnect/getDataBaseList",
            data: {},
            datatype: "json",
            success: function (res) {
                let data = JSON.parse(res)
                if (data.code == 200) {
                    selectdata = data.data
                    data.data.map(item => {
                        $('#selectDatabase').append(`<option value="${item.NAME}" label="${item.NAME}">${item.NAME}</option>`)
                    })
                } else {
                    layui.layer.msg(data.msg, {
                        time: 1000,
                        icon: 5,
                        shift: 6
                    })
                }
                layui.form.render("select");
            }
        });
        // 分析工具 数据的获取
        $.ajax({
            type: "post",
            async: false,
            url: modelApi + "dict/getDataDict",
            data: {
                name: 'analysisType'
            },
            datatype: "json",
            success: function (res) {
                let data = JSON.parse(res)
                if (data.code == 200) {
                    analysisToolsData = data.data
                    data.data.map(item => {
                        $('#analysisTools').append(`<option value="${item.ZDTITLE},${item.ZDVALUE}" name='analysisTools' label="${item.ZDTITLE}">${item.ZDTITLE}</option>`)
                    })
                } else {
                    layui.layer.msg(data.msg, {
                        time: 1000,
                        icon: 5,
                        shift: 6
                    })
                }
                layui.form.render("select");
            }
        });
        // 应用分类 数据的获取 
        $.ajax({
            type: "post",
            async: false,
            url: modelApi + "dict/getDataDict",
            data: {
                name: 'spatial'
            },
            datatype: "json",
            success: function (res) {
                let data = JSON.parse(res)
                if (data.code == 200) {
                    applicationClassificationData = data.data
                    data.data.map(item => {
                        $('#applicationClassification').append(`<option value="${item.ZDVALUE}" label="${item.ZDTITLE}">${item.ZDTITLE}</option>`)
                        $('#application').append(`<option value="${item.ZDVALUE}" label="${item.ZDTITLE}">${item.ZDTITLE}</option>`)
                    })
                } else {
                    layui.layer.msg(data.msg, {
                        time: 1000,
                        icon: 5,
                        shift: 6
                    })
                }
                layui.form.render("select");
            }
        });
    }
    // 查询按钮 
    function queryMethods(name) {
        $.ajax({
            type: "post",
            async: false,
            url: modelApi + "apply/getApplyByKey",
            data: {
                /*
                getApplyByKey(String name, String status, String registerTime,String userNo)
                name：表格名字   status:启动 注销   status:admin
                */
                name: name,
                status: $('#status').val(),
                registerTime: $('#selectTime').val(),
                userNo: portaluserno,
                systemType: $('#application').val()
            },
            datatype: "json",
            success: function (res) {
                let data = JSON.parse(res)
                if (data.code == 200) {
                    data.data.map(item => {
                        return item.REGISTER_DATE = formatDate(item.REGISTER_DATE)
                    }) 
                    if ($('#ipt_search').val() != '') {
                        queryData = data.data 
                        drawingTable(data.data, ['NAME', 'ANALYSIS_TOOLS', 'SYSTEM_STATUS', 'REGISTER_DATE'])
                    } else { 
                        drawingTable(data.data, ['NAME', 'ANALYSIS_TOOLS', 'SYSTEM_STATUS', 'REGISTER_DATE'])
                    }
                    sessionStorage.setItem('myApplication_curr',1) 
                } else {
                    layui.layer.msg(data.msg, {
                        time: 1000,
                        icon: 5,
                        shift: 6
                    })
                }
                layui.form.render("select");
            }
        });
    }
    $('#query').on('click', function () {
        // resourcesName   || status  ||    selectTime 
        queryMethods ($('#ipt_search').val()) 
    })
    $('#btn_reset').on('click', function () {
        resetType = true 
        $("#ipt_search").val('');
        $('#application').val('') 
        sessionStorage.setItem('myApplication_curr',1)
        getDataTable()
        drawingTable(tableData, ['NAME', 'ANALYSIS_TOOLS', 'REGISTER_DATE']) // 页面加载调用的函数 layui-form-onswitch
    })
    $(".registeredApplication").on('click', function () {
        layer.open({
            type: 2,
            title: '注册应用服务',
            shadeClose: true,
            shade: 0.8,
            area: ['800px', '700px'],
            content: '/BasePlatform/applicationSystem/dispose.html', //iframe的url
            // btn: ['确定', '取消'],
            // yes: function (index, layero) {
            //     console.log($('#selectDatabase').val());
            //     var iframe = window['layui-layer-iframe' + index];
            //     iframe.$("[name='preserveDeploy']").click();
            //     layer.close(index);
            //     layer.msg('注册成功', {
            //         icon: 1,
            //         time: 1500,
            //         shade: [0.5, '#000', true]
            //     });
            // },
            btn2: function (index, layero) {
                layer.close(index);
            },
            end: function () {
                getDataTable()
                drawingTable(tableData, ['NAME', 'ANALYSIS_TOOLS', 'REGISTER_DATE']) // 页面加载调用的函数 layui-form-onswitch
            },
        });
    })

    function drawingTable(data, arr) { 
        let ismangger = getUserRole () 
        data.map(item => {
            return Object.assign(item,{
                ismanger : ismangger 
            })
        })
        layui.table.render({
            elem: '#demo',
            data: data,
            page: {
                limit:20,
                curr:sessionStorage.getItem('myApplication_curr') ? sessionStorage.getItem('myApplication_curr') : 1
            }, 
            done:function (res,curr,count) {
                sessionStorage.setItem('myApplication_curr',curr)
            },
            cols: [
                [ //表头 
                    {
                        type: 'numbers',
                        title: '序号',
                        sort: true,
                        width: 80,
                        align: "center"
                    },
                    {
                        field: arr[0],
                        width: 250,
                        title: '服务名称',
                        align: 'center'
                    }, {
                        field: arr[1],
                        title: '服务类型',
                        align: 'center'
                    }, {
                        field: 'SYSTEM_STATUS',
                        title: '运行管理',
                        toolbar: '#operationManDiv',
                        align: "center"
                    }, {
                        field: 'operation',
                        title: '操作',
                        align: 'center',
                        toolbar: '#delivery-table-operate'
                    }
                ]
            ]
        })
    }
    $('#preserveDeploy').on('click', function () {
        layer.closeAll()
    }) 
    function getUserRole() {
        // （0  普通用户  1   部门管理员   2  系统管理员）
        var results = sendAjax(modelApi + "user/getUserIsManager", "POST", {
            userNo: portaluserno
        }); 
        if (results.code == 200) {
            return results.data.ISMANAGER
        } else {
            return null;
        }
    }
    
    function sendAjax(url, type, data) {
        $.ajaxSettings.async = false;
        var results;
        $.ajax({
            type: type,
            dataType: "json",
            url: url,
            data: data,
            success: function(data) {
                results = data;
            },
            error: function(error) {
                results = error;
            }
        });
        return results;
    }
})
function compare(key) {
    return function (value1, value2) {
        var val1 = value1[key]; 
        var val2 = value2[key]; 
        return val1 - val2;
    }
}

